<?php
namespace Activity\Models;

class Activity extends Base
{
    public function initialize()
    {
        parent::initialize();
    }

    public function getSource()
    {
        return 'activity_config_list';
    }

    /**
     * @param $id
     *
     * @return bool|mixed
     */
    public function get($id)
    {
        if (!is_numeric($id)) {
            return false;
        }
        try {
            $query = 'SELECT `title`,`content` FROM `activity_config_list` WHERE id=' . $id . ' LIMIT 1';
            $ret   = $this->db()->query($query)->fetch();
            if ($ret !== false && is_array($ret) && count($ret) > 0) {
                return $ret;
            }
        } catch (\PDOException $ex) {
            $this->errorLog('SELECT', $this->db()->getSQLStatement(), $ex->getMessage(), __FILE__, __LINE__);
        }
        return false;
    }

    /**
     * @return array|bool
     */
    public function gets()
    {
        try {
            $query = 'SELECT `title`,`id` FROM `activity_config_list` WHERE `status`=1 ORDER BY `weight` DESC';
            $ret   = $this->db()->query($query)->fetchAll();
            if ($ret !== false && is_array($ret) && count($ret) > 0) {
                foreach ($ret as $k => $v) {
                    $ret[$k]['link'] = 'http://activity.scdscar.com/activity/index/show/' . trim($ret[$k]['id']);
                }
                return $ret;
            }
        } catch (\PDOException $ex) {
            $this->errorLog('SELECT', $this->db()->getSQLStatement(), $ex->getMessage(), __FILE__, __LINE__);
        }
        return false;
    }

}
